package com.mohan.dlxj.controller;

import com.mohan.dlxj.common.JsonResult;
import com.mohan.dlxj.common.R;
import com.mohan.dlxj.pojo.RoleList;
import com.mohan.dlxj.service.RoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;



@RestController
@CrossOrigin
@RequestMapping("role")
public class RoleController {
  @Autowired
  private RoleService roleService;

  @GetMapping("pageRole")
  public JsonResult pageRole(long page, long limit){
    JsonResult jsonResult= roleService.getRoleList(page,limit);
    return jsonResult;
  }

  @GetMapping("getAllNum")
  public R getAllNum() {
    Integer all = roleService.getRoleAll();
    R r = new R();
    r.setData(all);
    r.setCode(200);
    r.setMsg("成功");
    return r;
  }

  @GetMapping("getRoleById/{id}")
  public R getRoleById(@PathVariable Integer id) {
    RoleList role = roleService.getRoleById(id);
    R r = new R();
    r.setCode(200);
    r.setMsg("查询成功");
    r.setData(role);
    return r;
  }

  @PostMapping("updateRole")
  public R updateRole(RoleList roleList) {
    roleService.updateRole(roleList);
    R r = new R();
    r.setCode(200);
    r.setMsg("更新角色成功");
    return r;
  }

  @DeleteMapping("deleteRole/{id}")
  public R deleteRole(@PathVariable Integer id) {
    roleService.deleteRole(id);
    R r = new R();
    r.setCode(200);
    r.setMsg("删除角色成功");
    return r;
  }


  @PostMapping("saveRole")
  public R saveRole(RoleList roleList) {
    roleService.saveRole(roleList);
    R r = new R();
    r.setCode(200);
    r.setMsg("添加角色成功");
    return r;
  }
}
